var oScorm = pipwerks.SCORM;  	// define a SCORM object to interface with PIPWerks code
    
// This function initializes the course by connecting to the LMS and retrieving 
// the student's name.
function initCourse()
{
	var lmsConnected = oScorm.init();
	
	if( lmsConnected )
	{
        // always set the status to incomplete
		oScorm.set("cmi.lesson_status", "incomplete");
		oScorm.set("cmi.success_status", "unknown");
		oScorm.set("cmi.completion_status", "incomplete");
	}
}

// Call this function at the very end of the course when the final
// score has been calculated.
function setScore( nScore )
{
	if( oScorm != null )
	{
		oScorm.set("cmi.score.max", "100" );
		oScorm.set("cmi.score.min", "0" );
		oScorm.set("cmi.score.raw", ( nScore * 100 ) );
		oScorm.set("cmi.score.scaled", nScore );
	
	    // Set the values and status here
		// for now, just set it to passed and completed
		oScorm.set("cmi.success_status", "passed");
		oScorm.set("cmi.completion_status", "completed");
	}
}

// check to see if the certificate is available
function isCertificateAvailable()
{
	if( oScorm != null )
	{	
		if( oScorm.get("cmi.success_status" ) == "passed" && oScorm.get("cmi.completion_status" ) == "completed" )
			return true;
	}
	return false;
}

// return the user name
function getUserName()
{
	if( oScorm != null )
	{
		return oScorm.get("cmi.learner_name" );
	}
	return "Firstname Lastname";
}

// it will be up to each page to set the suspend data
function setSuspendData( sData )
{	
	if( oScorm != null )
	{
		oScorm.set( "cmi.suspend_data", sData );
	}
}

// return the suspend data
function getSuspendData()
{
	if( oScorm != null )
	{
		return oScorm.get( "cmi.suspend_data" );
	}
	return "";
}

// This function is called when the window is closed.  It saves and quits the course.
function finishCourse()
{
	oScorm.save();
	oScorm.quit();
}
